package com.xiaoran.user20012.controller;


import com.xiaoran.commonapi.entity.Rst;
import com.xiaoran.commonapi.tencent.Sms;
import com.xiaoran.user20012.entity.XrUser;
import com.xiaoran.user20012.service.IXrUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xiaoRan
 * @since 2022-03-10
 */
@RestController
@RequestMapping("/xr-user")
public class XrUserController {
    @Autowired
    IXrUserService userService;
    @Autowired
    Sms sms;
    @Autowired
    Rst rst;

    @PostMapping("/sendSms")
    public Object sendSms(String phone) {
        return sms.sendSms(phone);
    }

    @PostMapping("/login")
    public Rst login(String phone, Integer code) {
        XrUser user = userService.login(phone, code);
        if (user == null) {
            return rst.error("登录失败，验证码不存在或者错误");
        }
        return rst.success(user);
    }
}
